﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECONTACT.Bussiness;
using ECONTACT.DataLayer;
using System.Data;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.Editors.DateTimeAdv;

namespace ECONTACT.Controller
{
    public class GiaoVienCtrl
    {
        GiaoVienData m_GiaoVienData = new GiaoVienData();

        #region Hien thi ComboBox
        public void HienThiComboBox(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_GiaoVienData.LayDsGiaoVien();
            comboBox.DisplayMember = "MaGV";
            comboBox.ValueMember = "MaGV";
        }
        public void HienThiComboBoxTen(ComboBoxEx comboBox)
        {
            comboBox.DataSource = m_GiaoVienData.LayDsGiaoVien();
            comboBox.DisplayMember = "TenGV";
            comboBox.ValueMember = "MaGV";
        }
        #endregion

        #region Do du lieu vao DataGridView
        public void HienThi(DataGridView dGV, BindingNavigator bN)
        {
            BindingSource bS = new BindingSource();

            bS.DataSource = m_GiaoVienData.LayDsGiaoVien();
            bN.BindingSource = bS;
            dGV.DataSource = bS;
        }

        public void HienThi(DataGridViewX dGV,
                            TextBoxX txtMaGV,
                            TextBoxX txtTenGV,
                            DateTimeInput dtpNgaySinh,
                            TextBoxX txtGioiTinh,
                            CheckBoxX ckbGTinhNam,
                            CheckBoxX ckbGTinhNu,
                            TextBoxX txtSDT,
                            TextBoxX txtEmail,
                            TextBoxX txtDiaChi)
        {
            BindingSource bS = new BindingSource();
            bS.DataSource = m_GiaoVienData.LayDsGiaoVien();

            DataTable dT = m_GiaoVienData.LayDsGiaoVien();
            bool gioiTinh = Convert.ToBoolean(dT.Rows[0]["GioiTinh"]);

            if (gioiTinh)
            {
                ckbGTinhNu.Checked = true;
            }
            else
            {
                ckbGTinhNam.Checked = true;
            }

            txtMaGV.DataBindings.Clear();
            txtMaGV.DataBindings.Add("Text", bS, "MaGV");

            txtTenGV.DataBindings.Clear();
            txtTenGV.DataBindings.Add("Text", bS, "TenGV");

            txtGioiTinh.DataBindings.Clear();
            txtGioiTinh.DataBindings.Add("Text", bS, "GioiTinh");

            dtpNgaySinh.DataBindings.Clear();
            dtpNgaySinh.DataBindings.Add("Value", bS, "NgaySinh");

            txtSDT.DataBindings.Clear();
            txtSDT.DataBindings.Add("Text", bS, "SDT");

            txtEmail.DataBindings.Clear();
            txtEmail.DataBindings.Add("Text", bS, "Email");

            txtDiaChi.DataBindings.Clear();
            txtDiaChi.DataBindings.Add("Text", bS, "DiaChi");

            //bN.BindingSource = bS;
            dGV.DataSource = bS;
        }
        #endregion

        public String LuuGiaoVien(String TenGV, DateTime NgaySinh, bool GioiTinh, String SDT, String Email, String DiaChi)
        {
            return m_GiaoVienData.LuuGiaoVien(TenGV, NgaySinh, GioiTinh, SDT, Email, DiaChi);
        }

        public String UpdateGiaoVien(String MaGV, String TenGV, DateTime NgaySinh, bool GioiTinh, String SDT, String Email, String DiaChi)
        {
            return m_GiaoVienData.UpdateGiaoVien(MaGV, TenGV, NgaySinh, GioiTinh, SDT, Email, DiaChi);
        }

        public void DeleteGiaoVien(String MaGV)
        {
            m_GiaoVienData.DeleteGiaoVien(MaGV);
        }
    }
}
